package fibonacci;

import java.util.Scanner;
import songuyenlon.SoNguyenLon;

public class FibonacciNumber{
	final static SoNguyenLon Mot = new SoNguyenLon("1");
	
	/*
	 * Ham tinh so fibonacci:
	 * Input: so nguyen lon can tinh so fibonacci.
	 * Output: so nguyen lon gia tri fiboncci sau khi tinh.
	 */
	
	private static SoNguyenLon fibonacci(SoNguyenLon n){
		SoNguyenLon f1 = new SoNguyenLon("0");
		SoNguyenLon f2 = new SoNguyenLon("1");
		SoNguyenLon i = new SoNguyenLon("0");
		while(n.Sosanh(i) == 1){
			SoNguyenLon val = f1;
			f1 = f2;
			f2 = f2.Cong(val);
			i = i.Cong(Mot);
		}
		return f1;
	}
	
	/*
	 * Ham main()
	 */
	
	public static void main(String[] args) {
		long start, stop;
		Scanner s = new Scanner(System.in);
        System.out.print("Tinh fibonacci cua: ");
        long m = s.nextLong();
        SoNguyenLon n = new SoNguyenLon(m);
		start = System.currentTimeMillis();	
		fibonacci(n).In();
		stop = System.currentTimeMillis();
		System.out.println("Thoi gian tinh: "+(stop - start));
	}
}
